package handler

import (
	"github.com/gin-gonic/gin"
	"hound-sys/models"
)

func Urole(c *gin.Context) {

	var data []models.Role
	uid := c.PostForm("uid")
	/*
		SELECT
		*
		FROM
		roles
		LEFT JOIN user_roles ON user_roles.rid = roles.id
		WHERE user_roles.uid = 1
	*/

	models.DB.Table("roles").
		Joins("LEFT JOIN user_roles ON user_roles.rid = roles.id").
		Where("user_roles.uid = ?", uid).Debug().
		Find(&data)

	c.JSON(200, gin.H{
		"code": 200,
		"smg":  "成功",
		"data": data,
	})
	return
}
func Rnode(c *gin.Context) {
	var data []models.Node

	/*
		SELECT
		  *
		FROM
		  nodes
		  LEFT JOIN role_nodes ON role_nodes.nid = nodes.id
		WHERE
		  role_nodes.rid = 1
	*/
	rid := c.PostForm("rid")
	models.DB.Table("nodes").
		Joins("LEFT JOIN role_nodes ON role_nodes.nid = nodes.id").
		Where("role_nodes.rid = ?", rid).Debug().
		Find(&data)

	c.JSON(200, gin.H{
		"code": 200,
		"smg":  "成功",
		"data": data,
	})
	return
}
